{# Stalker Pyramid a Web Base Production Asset Management System
 Copyright (C) 2009-2014 Erkan Ozgur Yilmaz

 This file is part of Stalker Pyramid.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation;
 version 2.1 of the License.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#}

{% extends "base.jinja2" %}

{# BREADCRUMBS #}
{% block breadcrumbs %}

    {% set page_title='Users' %}
    {% include 'breadcrumb/breadcrumbs.jinja2' %}

{% endblock breadcrumbs %}

{# SIDEBAR #}
{% block sidebar %}

    {% include 'sidebar.jinja2' %}

{% endblock sidebar %}

{# PAGE-CONTENT #}
{% block page_content %}

    {% set page_title='Users' %}
    {% include 'page_header.jinja2' %}


    {% if entity.entity_type == 'Studio' %}
        {% set address=request.route_path('get_users') %}
        {% set add_button_address=request.route_path('create_user_dialog') %}
    {% else %}
        {% set address=request.route_path('get_entity_users', id=entity.id) %}
        {% set add_button_title='Add' %}
        {% set add_button_address=request.route_url('append_entities_to_entity_dialog', id=entity.id, entities='User', _query={'came_from': request.current_route_path()}) %}
    {% endif %}


    {% set list_item_type='User' %}
    {% include 'components/data_table.jinja2' %}

{% endblock page_content %}

{# EXTRA-SCRIPTS #}
{% block extrascripts %}
    {% raw %}
    <script id="tmpl_itemThead" type="text/x-dot-template">

        <tr>
            <th>Thumbnail</th>
            <th>Name</th>
            <th>Email</th>
            <th>Tasks Count</th>
            <th>Tickets Count</th>
            <th>Status</th>
            <th></th>
        </tr>
    </script>
    {% endraw %}

    {% raw %}
    <script id="tmpl_itemRow" type="text/x-dot-template">
        <tr>
            <td><img style='width:auto; height: 100px;'
                     class="img-thumbnail"
                     src="{{=it.thumbnail_full_path }}">
            </td>
            <td><a href='/users/{{=it.id}}/view'>{{=it.name}}</a>
            </td>
            <td><a href='/users/{{=it.id}}/view'>{{=it.email}}</a>
            </td>
            <td>{{=it.tasksCount}}
            </td>
            <td>{{=it.ticketsCount}}
            </td>
            <td>
                <span class="label label-{{=it.status_color}}">{{=it.status}}</span>
            </td>
            <td>
                {{ if (it.update_user_action) { }}
                <a class="blue"

                   href="{{=it.update_user_action}}">
                    <i class="icon-edit bigger-130"></i>
                </a>
                {{ } }}

                {{ if (it.delete_user_action) { }}
                <a class="red"
                   data-target="#dialog_template"
                   data-toggle="modal"
                   data-keyboard=false
                   href="{{=it.delete_user_action}}?came_from={{=it.came_from }}">
                    <i class="icon-trash bigger-130"></i>
                </a>
                {{ } }}
            </td>
        </tr>
    </script>
    {% endraw %}

    <script>

        var tableParameters = {"aoColumns": [null, null, null, {'sType': 'num-html'},{'sType': 'num-html'},null, null]}
        var sortingParameters = [[0, 'asc']]
        var tableDataAddress = '{{ request.route_path('get_entity_users', id=entity.id) }}'

        {% if entity.entity_type == 'Studio' %}
            tableDataAddress = '{{ request.route_path('get_users') }}'
        {% else %}
            tableDataAddress = '{{ request.route_path('get_entity_users', id=entity.id) }}'

        {% endif %}

    </script>

{% endblock extrascripts %}

